package global

import (
	"github.com/sirupsen/logrus"
	"hcy-api/lib/db"
	"path/filepath"
)

func InitDB() {
	var err error
	DB, err = db.GetDB(Conf.DB.Supper, Conf.DB.ShowSqlLog, Conf.DB.Source, Conf.AppFolder)
	if err != nil {
		logrus.Panicf("source file path：%v", filepath.Join(Conf.AppFolder, "data", Conf.DB.Source))
	}
	autoMigrate()
}

func autoMigrate() {
	type vector[T any] []T
	var li = vector[interface{}]{
		// 初始化数据库
	}
	for _, item := range li {
		if !DB.Migrator().HasTable(item) {
			err := DB.AutoMigrate(item)
			if err != nil {
				logrus.Errorf("初始化数据库表结构异常: %v", err)
			}
		}
	}
}
